package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.AdvertiseService;
import com.junzhiit.nengji.cms.web.vo.AdvertiseAddVO;
import com.junzhiit.nengji.cms.web.vo.AdvertiseEditVO;
import com.junzhiit.nengji.cms.web.vo.AdvertiseVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/advertise")
public class AdvertiseController extends BaseController {

	@Autowired
	private AdvertiseService advertiseService;

	@ApiOperation(value = "获取所有广告列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, AdvertiseVO advertiseVO) {
		return advertiseService.findAll(dtp, advertiseVO);
	}

	@ApiOperation(value = "根据ID查询广告")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseService.findById(id);
	}

	@ApiOperation(value = "创建广告")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(AdvertiseAddVO advertiseAddVO) {
		AssertUtil.notBlank(advertiseAddVO.getAdvertiseTypeId(), "advertiseTypeId is required.");
		AssertUtil.notBlank(advertiseAddVO.getAdvertiseUrl(), "advertiseUrl is required.");
		AssertUtil.notBlank(advertiseAddVO.getImgUrl(), "imgUrl is required.");
		return advertiseService.add(advertiseAddVO);
	}

	@ApiOperation(value = "修改广告")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(AdvertiseEditVO advertiseEditVO) {
		AssertUtil.notBlank(advertiseEditVO.getAdvertiseTypeId(), "advertiseTypeId is required.");
		AssertUtil.notBlank(advertiseEditVO.getAdvertiseUrl(), "advertiseUrl is required.");
		AssertUtil.notBlank(advertiseEditVO.getImgUrl(), "imgUrl is required.");
		return advertiseService.edit(advertiseEditVO);
	}

	@ApiOperation(value = "删除广告")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseService.delete(id);
	}

	@ApiOperation(value = "置顶")
	@RequestMapping(value = "/toTop", method = RequestMethod.PUT)
	public ResultVO toTop(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseService.toTop(id);
	}

	@ApiOperation(value = "改变status")
	@RequestMapping(value = "/change/status", method = RequestMethod.PUT)
	public ResultVO changeStatus(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return advertiseService.changeStatus(id);
	}

	@ApiOperation(value = "删除广告图片")
	@RequestMapping(value = "/pic", method = RequestMethod.DELETE)
	public ResultVO delAdvertisePic(String id) {
		return advertiseService.delAdvertisePic(id);
	}

}
